FROM node:20-alpine as builder

WORKDIR /app

# 复制所有文件
COPY . .

# 使用yarn安装依赖
RUN yarn config set registry https://mirrors.cloud.tencent.com/npm/ \
  && yarn install \
  && yarn global add @nestjs/cli

RUN yarn build

# 生产阶段
FROM node:20-alpine

WORKDIR /app

COPY --from=builder /app/dist ./dist
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./

EXPOSE 7001

CMD ["yarn", "start"]